package com.fan.gofast.dtos;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Date: 2020/2/20 11:33 PM
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class BaseResponse<T> {

    public static final int SUCCESS = 0;

    protected int code = SUCCESS;

    protected String message = "成功";

    @JsonInclude(JsonInclude.Include.NON_NULL)
    protected T data;

    public BaseResponse(int code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 只打印code、message，日志级别在info(含)以上使用
     *
     * @return
     */
    public String toShortString() {
        final StringBuilder sb = new StringBuilder("BaseResponse(");
        sb.append("code=").append(code);
        sb.append(", message=").append(message);
        sb.append(')');
        return sb.toString();
    }


}
